<?php
namespace app\admin\controller;
use think\Controller;
use think\Controllers;
use think\Session;
use think\Cookie;
use think\Jump;
use think\Db;
class Daikuan extends Controllers{

		public function index()
		{
				$pindex    = max(1, intval($_GPC['page']));

				$psize     = 20;
				$wheres = " AND uniacid= 2 ";

				$sql = "SELECT * FROM  ims_xuan_zy_daikuan  WHERE  1 {$wheres}";

				$sql .= " limit " . ($pindex - 1) * $psize . ',' . $psize;
				$list   =  DB::query($sql);
				$total  = DB::query("select count(*) as count from ims_xuan_zy_daikuan WHERE 1 {$wheres}")[0]['count'];
				$pager  = $this->pagination($total, $pindex, $psize);
				$this->assign("list",$list);
				return $this->fetch("admin/daikuan");
		}
		public function add(){

		if(request()->isget()){
			$id = isset($_GET['id'])?$_GET['id']:0;
			if($id!=0){
				$sql ="select * from ims_xuan_zy_daikuan where id ={$id}";
				$arr = DB::query($sql)[0];
				$arr['content'] = json_decode($arr['content'],true);
				$arr['fy'] = json_decode($arr['fy'],true);
				$this->assign("arr",$arr);	
			}
			return $this->fetch("admin/daikuan_add");

		} else {

			$data=array(
				'renshu'=>$_POST['renshu'],
				'huan'=>$_POST['huan'],
				'qixian'=>$_POST['qixian'],
				'jianjie'=>$_POST['jianjie'],
				'xuzhi'=>$_POST['xuzhi'],
				'lianxi'=>$_POST['lianxi'],
				'jieshao'=>$_POST['jieshao']
			);
			$_GPC['da']['ico'] = $_POST['ico'];
			$_GPC['da']['logo'] = $_POST['logo'];
			$_GPC['da']['content'] = json_encode($data);
			$fy = ["type"=>$_POST['type'],"sx"=>$_POST['sx']];
	        $_GPC['da']['fy'] = json_encode($fy);
			$_GPC['da']['createtime'] = time();
			$_GPC['da']['uniacid'] = 2;
			$_GPC['da']['name'] = $_POST['name'];
			$_GPC['da']['yjjieshao'] = $_POST['yjjieshao'];
			$_GPC['da']['jiangjin'] = $_POST['jiangjin'];
			$_GPC['da']['rate'] = $_POST['rate'];
			$_GPC['da']['edu'] = $_POST['edu'];
			$_GPC['da']['poster_id'] = $_POST['poster_id'];
			$_GPC['da']['speed'] = $_POST['speed'];
			$_GPC['da']['url'] = $_POST['url'];
			$_GPC['da']['rank'] = $_POST['rank'];
			$_GPC['da']['status'] = $_POST['status'];
			if(!empty($_POST['id'])){
			DB::table('ims_xuan_zy_daikuan')->where("id","{$_POST['id']}")->setField($_GPC['da']);
			$this->success("修改成功","admin/daikuan/index");

			}else {

			DB::table('ims_xuan_zy_daikuan')->insert($_GPC['da']);
			$this->success("添加成功","admin/daikuan/index");
			}
		
			
		}
	}
		public function del(){
		$id = $_POST['id'];
		$sql ="delete from ims_xuan_zy_daikuan  where id = {$id}";
		DB::query($sql);
		return true;
	}

}